package com.navinfo.opentsp.platform.computing.analysis.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;


/**
 * 瓦片与区域缓存
 */
public class AreaTileCache implements Serializable{

    public static Logger log = LoggerFactory.getLogger(AreaTileCache.class);

    private static HashMap<Long, HashSet<Long>> cache = new HashMap<>();


    public AreaTileCache() {
    }

    /**
     * 添加瓦片与区域关系
     * @param tileId
     * @param areaId
     */
    public void addAreaTile(long tileId,Long areaId) {
        HashSet<Long> areaIds = cache.get(tileId);
        if(areaIds == null){
            areaIds = new HashSet<Long>();
            cache.put(tileId, areaIds);
        }
        areaIds.add(areaId);
    }

    /**
     * 删除瓦片与区域关系
     * @param tileId
     * @param areaId
     */
    public void removeArea(long tileId,Long areaId) {
        HashSet<Long> areaIds = cache.get(tileId);
        if(areaIds != null){
            areaIds.remove(areaId);
        }
    }

    public HashMap<Long, HashSet<Long>> getAreaTileCache() {
        return cache;
    }

    /**
     * 获得瓦片所包含的区域
     * @param tileId
     * @return
     */
    public HashSet<Long> getAreaTile(long tileId) {
        return cache.get(tileId);
    }

    public static void main(String[] args) {
        AreaTileCache areaTileCache = new AreaTileCache();
        areaTileCache.addAreaTile(1L,2L);
        areaTileCache.addAreaTile(1L,3L);
        System.out.println(areaTileCache.getAreaTile(1L).toString());
        //;
    }

}
